home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / undo / undoRemoveRootEntry.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  4.8 KB  |  193 lines

  1. /*
  2.  *   $RCSfile: undoRemoveRootEntry.c,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:56:03 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37.  
  38.  
  39. #include "sysdefs.h"
  40. #include "ess.h"
  41. #include "checking.h"
  42. #include "trace.h"
  43. #include "error.h"
  44. #include "list.h"
  45. #include "pool.h"
  46. #include "tid.h"
  47. #include "io.h"
  48. #include "lock.h"
  49. #include "object.h"
  50. #include "msgdefs.h"
  51. #include "thread.h"
  52. #include "latch.h"
  53. #include "semaphore.h"
  54. #include "link.h"
  55. #include "lsn.h"
  56. #include "bf.h"
  57. #include "log.h"
  58. #include "volume.h"
  59. #include "logrecs.h"
  60. #include "undo.h"
  61. #include "io_logfuncs.h"
  62. #include "io_extfuncs.h"
  63. #include "undo_extfuncs.h"
  64. #include "bf_extfuncs.h"
  65. #include "util_funcs.h"
  66. #include "thread_globals.h"
  67.  
  68.  
  69.  void
  70. undoRemoveRootEntry (
  71.  
  72.     LOGRECORDHDR        *recordHeader 
  73. )
  74. {
  75.  
  76.     register ROOTENTRY    *current;
  77.     register ROOTENTRY    *end;
  78.     register VOLREC        *volRec;
  79.     register GROUPLINK    *rootLink;
  80.     ROOTPAGE            *rootPage;
  81.     char                *oldData;
  82.     int                    oldDataSize;
  83.     PID                    pid;
  84.     VOLID                volid;
  85.     ROOTENTRYLOGINFO    *entryInfo;
  86.  
  87.  
  88.     TRPRINT(TR_IO, TR_LEVEL_1, ("lsn:%d", recordHeader->recordLSN));
  89.  
  90.     /*
  91.      *    get a pointer to the volume id in the record
  92.      */
  93.     volid = recordHeader->actionPid.volid;
  94.     TRPRINT(TR_IO, TR_LEVEL_2, ("volid:%d", volid));
  95.  
  96.     /* get a pointer to information about the entry */
  97.     entryInfo = (ROOTENTRYLOGINFO*) GET_LOG_IMAGE(recordHeader, 0);
  98.     TRPRINT(TR_IO, TR_LEVEL_2, ("name:%s", entryInfo->name));
  99.     TRPRINT(TR_IO, TR_LEVEL_2, ("oldFlags:%d", entryInfo->oldFlags));
  100.  
  101.     /*
  102.      *    get a pointer to the old data and its size in the record
  103.      */
  104.     oldData = GET_LOG_IMAGE(recordHeader, 1);
  105.     oldDataSize = GET_LOG_IMAGE_SIZE(recordHeader, 1);
  106.     TRPRINT(TR_IO, TR_LEVEL_2, ("oldData:%s", oldData));
  107.  
  108.     if ((volRec = io_FindVolRec(volid)) == NULL)    {
  109.         SM_ERROR(TYPE_FATAL, Active->errno);
  110.     }
  111.  
  112.     /*
  113.      *    construct the pid of the header page
  114.      */
  115.     pid.volid = volid;
  116.     pid.page  = ROOTPAGEADDR;
  117.     SM_ASSERT(LEVEL_3, ROOTPAGEADDR == recordHeader->actionPid.page);
  118.  
  119.     /*
  120.      *    read in the root page
  121.      */
  122.     if ((rootLink = bf_ReadPage(volRec->bufGroup, &pid, MIN_PAGE2SIZE, BF_SEM)) == NULL) {
  123.  
  124.         SM_ERROR(TYPE_FATAL, Active->errno);
  125.     }
  126.  
  127.     /*
  128.      *    get a pointer to the root page
  129.      */
  130.     rootPage = (ROOTPAGE *) rootLink->bufFrame;
  131.  
  132.     /*
  133.      *    Initialize the search variables
  134.      */
  135.     current = &(rootPage->entry[0]);
  136.     end = &(rootPage->entry[MAX_ROOT_ENTRIES]);
  137.     
  138.     /*
  139.      *    look for a free spot
  140.      */
  141.     while (current < end)    {
  142.  
  143.         /*
  144.          *    check to see if the slot is free
  145.          */
  146.         if (current->flags != ROOT_FREE)    {
  147.  
  148.             /*
  149.              *    check to see if the name matches
  150.              */
  151.             if (!strcmp(current->name, (char *)entryInfo->name))    {
  152.                 
  153.                 /* this was removed, so it should not be here */
  154.                 SM_ERROR(TYPE_FATAL, esmINTERNAL);
  155.             }
  156.         
  157.         } else {
  158.  
  159.             /* log the changes */
  160.             if (io_LogSetRootEntry(current->name,
  161.                 oldData, 0, /* this is minimum filler for old value */
  162.                 oldData, oldDataSize, ROOT_FREE, rootLink->pageHash,
  163.                 &(recordHeader->previousLSN) ))    {
  164.  
  165.                 bf_UnfixPage(rootLink, BF_DEFAULT, FALSE);
  166.                 SM_ERROR(TYPE_FATAL, Active->errno);
  167.             }
  168.         
  169.  
  170.             /* Restore the old data */
  171.             strncpy(current->name, (char*) entryInfo->name, MAX_ROOTNAME_SIZE);
  172.             bcopy(oldData, current->data, oldDataSize);
  173.             current->dataSize = oldDataSize;
  174.             current->flags = ROOT_USED;
  175.  
  176.             /* signal the semaphore and unfix the page */
  177.             signalSemaphore( &(rootLink->pageHash->semaphore) );
  178.             bf_UnfixPage(rootLink, BF_DEFAULT, TRUE);
  179.     
  180.             return;
  181.         }
  182.  
  183.         /* look at the next entry */
  184.         current++;
  185.     }
  186.  
  187.     /*
  188.      *    return an error
  189.      */
  190.     TRPRINT(TR_IO, TR_LEVEL_2, ("no space for root name"));
  191.     SM_ERROR(TYPE_FATAL, esmBADROOTNAME);
  192. }
  193.